package com.xmxsuperstar.app.client.twitter;

import java.util.ArrayList;
import java.util.List;

import net.love5z.common.json.JSONArray;
import net.love5z.common.json.JSONException;
import net.love5z.common.json.JSONObject;
import android.util.Log;

import com.xmxsuperstar.app.client.ClientConstants;
import com.xmxsuperstar.app.client.twitter.model.TwitterList;

public class TwitterAllListClient extends TwitterClient {

	private static final String baseUrlStr = "http://api.twitter.com/1/lists/all.json";

	public List<TwitterList> getAllList() {
		String response = this.get(baseUrlStr);
		return parase(response);
	}

	protected List<TwitterList> parase(String content) {
		List<TwitterList> list = new ArrayList<TwitterList>();

		try {
			JSONArray allListArray = new JSONArray(content);
			for (int i = 0; i < allListArray.length(); i++) {
				JSONObject st = allListArray.getJSONObject(i);

				TwitterList twitterList = new TwitterList();
				twitterList.setId(st.getLong("id"));
				twitterList.setName(st.getString("name"));
				twitterList.setSlug(st.getString("slug"));
				twitterList.setDescription(st.getString("description"));

				list.add(twitterList);
			}
		} catch (JSONException e) {
			Log.e(ClientConstants.LogTag, e.getMessage());
		}

		return list;
	}

	public static void main(String[] args) {
		TwitterAllListClient tac = new TwitterAllListClient();
		System.out.println(tac.getAllList());
	}

}
